package login.Controller.userInformation;

import login.Model.dao.VerifiCode;

import javax.imageio.ImageIO;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.descriptor.JspConfigDescriptor;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Map;
import java.util.Set;

@WebServlet(name = "verifiCodeServlet",value = "/verifiCode")
public class verifiCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //生成验证码
        VerifiCode vc = new VerifiCode();
        //将验证码上的文本存入Session中
        ImageIO.write(vc.getImage(),"JPG",resp.getOutputStream());
        String verifyCode = vc.getCodes();
        System.out.println(vc.getCodes());
        HttpSession session = req.getSession();
        session.setAttribute("verifyCode",verifyCode);
        System.out.println(req.getSession().getAttribute("verifyCode"));

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
